


/*
--------------------------------------------------------------------------------------------------------
The following code is to replicate all results in Tables A21- A23 (in Appendix) in Rodrigue et al. (2022)
--------------------------------------------------------------------------------------------------------
The meanings of each variable:

1. lnso2: firm-level emission intensity of so2;
2. lndust: firm-level emission intensity of industrial dust;
3. Abatement_so2: firm-level abatement in so2;
4. Abatement_dust: firm-level abatement in dust;
5. lnKL: firm-level capital to labor ratio
6. Tariff: tariff
7. lnso2_ini: initial level of so2 emission intensity;
8. lndust_ini: initial level of dust emission intensity;
9. tariff_prod: initial tariff* initial-producivity
10. ventilation: ventilation coefficients for each province in each year;
11. ventilation_prod: ventilation coefficient * initial productivity
12. cic: 4-digit industry classification 
13. prov: province
14. ownership: SOE (ownerships==1|ownerships==2); private (ownerships==3); foreign (ownerships==4|ownerships==5);
15. cic_year, prov_year, owner_year: industry-year, province-year and ownership-year dummies. 
16. exp_tfp: interaction of firm-level export status and TFP
19. abt_so2_exp: interaction of firm-level abatement and export status
20. lnso2_d; lndust_d, tfp_acf_new_d, etc: denote the first difference variables at firm-level 
21. lnvintage: capital vintage
22. NRG: firm-level energe usage
23. Imp_NRG: firm-level imported energe
24. Imp_abt: imported abatement equipment
25. Mix: export product mix
26. Demand: the meausre of cross-country measure of demand for clean production
*/







*****************************Table A21****************************************************
*****************************Table A21****************************************************
*****************************Table A21****************************************************
  
 use "D:\Nanjing\2019\pollution2\submission\files for submission\data\correlation",clear
 set matsize 10000
*gen lnvintage=-lnv_lag
*gen Mix=1/ln(dirty_so2)
rename exp_dummy Export
rename export  Exp_value
rename so2_new1 Abatement_so2
rename tfp_acf1 Productivity
rename coal_share_lag NRG
*rename dirty_so2 Mix
rename lnkl_lag lnKL
rename cic_so2 Demand
rename indc_e Imp_NRG
rename indc_abt Imp_abt
rename lnv_lag vintage



areg lnso2 i.year i.ownerships , a( prov) 
capture drop e_so2
predict e_so2, residuals
replace  lnso2=e_so2

areg Export i.year i.ownerships i.prov, a(cic) 
capture drop e_Export
predict e_Export, residuals
replace  Export=e_Export

areg Exp_value i.year i.ownerships i.prov, a(cic) 
capture drop e_Exp_value
predict e_Exp_value, residuals
replace  Exp_value=e_Exp_value


areg Abatement_so2 i.year i.ownerships i.prov, a(cic) 
capture drop e_Abatement_so2
predict e_Abatement_so2, residuals
replace  Abatement_so2=e_Abatement_so2


areg Productivity i.year i.ownerships i.prov, a(cic) 
capture drop e_Productivity
predict e_Productivity, residuals
replace  Productivity=e_Productivity

areg lnRD i.year i.ownerships i.prov, a(cic) 
capture drop e_lnRD
predict e_lnRD, residuals
replace  lnRD=e_lnRD

areg lnvintage i.year i.ownerships i.prov, a(cic) 
capture drop e_lnvintage
predict e_lnvintage, residuals
replace  lnvintage=e_lnvintage



areg NRG i.year i.ownerships i.prov, a(cic) 
capture drop e_NRG
predict e_NRG, residuals
replace  NRG=e_NRG


areg Imp_NRG i.year i.ownerships i.prov, a(cic) 
capture drop e_Imp_NRG
predict e_Imp_NRG, residuals
replace  Imp_NRG=e_Imp_NRG


areg Imp_abt i.year i.ownerships i.prov, a(cic) 
capture drop e_Imp_abt
predict e_Imp_abt, residuals
replace  Imp_abt=e_Imp_abt


areg Mix i.year i.ownerships i.prov, a(cic) 
capture drop e_Mix
predict e_Mix, residuals
replace  Mix=e_Mix

/*
areg Demand i.year i.ownerships i.prov, a(cic) 
capture drop e_Demand
predict e_Demand, residuals
replace  Demand=e_Demand
*/
correlate lnso2 Export Exp_value Abatement_so2 Productivity lnRD lnvintage NRG Imp_NRG Imp_abt Mix Demand

replace Exp_value=log(Exp_value)
sum lnso2 Export Exp_value Abatement_so2 Productivity lnRD lnvintage NRG Imp_NRG Imp_abt Mix Demand








****************************Table A22*****************************************************
****************************Table A22*****************************************************
****************************Table A22*****************************************************
use "D:\Nanjing\2019\pollution2\submission\files for submission\data\correlation",clear

 set matsize 10000
*gen Mix=1/ln(dirty_dust)
rename exp_dummy Export
rename export  Exp_value
rename dust_new1 Abatement_dust
rename tfp_acf1 Productivity
rename coal_share_lag NRG
rename lnkl_lag lnKL
rename cic_so2 Demand
rename indc_e Imp_NRG
rename indc_abt Imp_abt
rename lnv_lag vintage



areg lndust i.year i.ownerships , a( prov) 
capture drop e_dust
predict e_dust, residuals
replace  lndust=e_dust

areg Export i.year i.ownerships i.prov, a(cic) 
capture drop e_Export
predict e_Export, residuals
replace  Export=e_Export

areg Exp_value i.year i.ownerships i.prov, a(cic) 
capture drop e_Exp_value
predict e_Exp_value, residuals
replace  Exp_value=e_Exp_value


areg Abatement_dust i.year i.ownerships i.prov, a(cic) 
capture drop e_Abatement_dust
predict e_Abatement_dust, residuals
replace  Abatement_dust=e_Abatement_dust
replace Abatement_dust=0 if so2_new1!=.& Abatement_dust==. 



areg Productivity i.year i.ownerships i.prov, a(cic) 
capture drop e_Productivity
predict e_Productivity, residuals
replace  Productivity=e_Productivity

areg lnRD i.year i.ownerships i.prov, a(cic) 
capture drop e_lnRD
predict e_lnRD, residuals
replace  lnRD=e_lnRD

areg lnvintage i.year i.ownerships i.prov, a(cic) 
capture drop e_lnvintage
predict e_lnvintage, residuals
replace  lnvintage=e_lnvintage



areg NRG i.year i.ownerships i.prov, a(cic) 
capture drop e_NRG
predict e_NRG, residuals
replace  NRG=e_NRG


areg Imp_NRG i.year i.ownerships i.prov, a(cic) 
capture drop e_Imp_NRG
predict e_Imp_NRG, residuals
replace  Imp_NRG=e_Imp_NRG


areg Imp_abt i.year i.ownerships i.prov, a(cic) 
capture drop e_Imp_abt
predict e_Imp_abt, residuals
replace  Imp_abt=e_Imp_abt

replace Imp_abt=0 if Imp_abt==.
replace Imp_NRG=0 if Imp_NRG==.

areg Mix i.year i.ownerships i.prov, a(cic) 
capture drop e_Mix
predict e_Mix, residuals
replace  Mix=e_Mix

/*
areg Demand i.year i.ownerships i.prov, a(cic) 
capture drop e_Demand
predict e_Demand, residuals
replace  Demand=e_Demand
*/
correlate lndust Export Exp_value Abatement_dust Productivity lnRD lnvintage NRG Imp_NRG Imp_abt Mix Demand

replace Exp_value=log(Exp_value)
replace Imp_abt=. if Imp_abt==0
replace Imp_NRG=. if Imp_NRG==0
sum lndust Export Exp_value Abatement_dust Productivity lnRD lnvintage NRG Imp_NRG Imp_abt Mix Demand









****************************Table A23*****************************************************
****************************Table A23*****************************************************
****************************Table A23*****************************************************
use "D:\Nanjing\2019\pollution2\submission\files for submission\data\correlation",clear


*gen lnvintage=-lnv_lag
rename exp_dummy Export
rename export  Exp_value
rename so2_new1 Abatement_so2
rename tfp_acf_new Productivity
rename coal_share_lag NRG
*rename dirty_so2 Mix
rename cic_so2 Demand
rename indc_e Imp_NRG
rename indc_abt Imp_abt
rename lnv_lag vintage

rename lnkl_lag lnKL
rename lntariff Tariff
rename treatment_tfp tariff_prod
rename treatment_so2 ventilation_prod
/*
replace Imp_NRG=0 if Imp_NRG==.
replace Imp_abt=0 if Imp_abt==.
keep Export cic RD_d lnvintage Mix lnso2_ini Exp_value Abatement_so2 Productivity NRG Demand party_id year prov ownerships Imp_NRG Imp_abt vintage lnKL Tariff tariff_prod ventilation_prod
save "D:\Nanjing\2019\pollution2\RR\data\correlation_update", replace
*/
*replace lnvintage=0 if lnvintage==.
replace Imp_NRG=0 if Imp_NRG==.
replace Imp_abt=0 if Imp_abt==.
ivreghdfe RD_d  (Export Abatement_so2 =tariff_prod ventilation_prod  ventilation )  Productivity Tariff lnKL  lnso2_ini  , a(cic prov year ownership) 

ivreghdfe lnvintage  (Export Abatement_so2  =tariff_prod ventilation_prod  ventilation   )  Productivity Tariff lnKL  lnso2_ini, a(cic  prov year ownership) cluster(prov_c)

ivreghdfe NRG  (Export Abatement_so2  =tariff_prod ventilation_prod  ventilation   )   Productivity Tariff lnKL  lnso2_ini, a(cic  prov year ownership) cluster(prov_c)

ivreghdfe Imp_NRG  (Export Abatement_so2  =tariff_prod ventilation_prod  ventilation   )   Productivity Tariff lnKL  lnso2_ini, a(cic  prov year ownership) cluster(prov_c)


ivreghdfe Imp_abt  (Export Abatement_so2 =tariff_prod ventilation_prod  ventilation )  Productivity Tariff lnKL  lnso2_ini, a(cic  prov year ownership) cluster(prov_c)


ivreghdfe Mix  (Export Abatement_so2  =tariff_prod ventilation_prod  ventilation   )   Productivity Tariff lnKL  lnso2_ini, a(cic  prov year ownership) cluster(prov_c)

ivreghdfe Demand  (Export Abatement_so2  =tariff_prod ventilation_prod  ventilation  )   Productivity Tariff lnKL  lnso2_ini, a(cic  prov year ownership) cluster(prov_c)

